package com.xoa.controller.workflow;

import com.xoa.model.users.Users;

import com.xoa.service.workflow.toBeRead.ToBeReadService;
import com.xoa.util.CookiesUtil;
import com.xoa.util.common.session.SessionUtils;
import com.xoa.util.common.wrapper.BaseWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;

@Controller
@RequestMapping(value = "/ToBeReadController")
public class ToBeReadController {
    @Autowired
    ToBeReadService toBeReadService;
    @RequestMapping("/toReadFile")
    public String toReadFile(){
        return "app/workflow/work/toReadFile";
    }

    @RequestMapping("/ReadFile")
    public String ReadFiletoReadFile(){
        return "app/workflow/work/ReadFile";
    }

    @RequestMapping("/ReadFileInfo")
    public String ReadFileInfo(){
        return "app/workflow/work/ReadFileInfo";
    }

    /**
     * 查询文件查阅情况（工作流、公文）
     * 王禹萌 2018-11-27
     * @param request
     * @param isReadStr
     * @param page
     * @param pageSize
     * @param useFlag
     * @param beginUser
     * @param beginTime
     * @param title
     * @return
     */
   @RequestMapping("/ReadFileIsRead")
   @ResponseBody
   public BaseWrapper ReadFileIsRead(HttpServletRequest request, String isReadStr, Integer page, Integer pageSize, Boolean useFlag,String beginUser,String beginTime,String title){
       Cookie redisSessionCookie = CookiesUtil.getCookieByName(request, "redisSessionId");
       Users user = SessionUtils.getSessionInfo(request.getSession(), Users.class, new Users(),redisSessionCookie);
     return toBeReadService.ReadFileIsRead(user.getUserId(),isReadStr,beginUser,beginTime,title,page,pageSize,useFlag);
   }

    /**
     * 批量删除已阅未阅文件
     * 王禹萌 2018-11-27
     * @param delStr
     * @return
     */
    @RequestMapping("/deleteFileIsRead")
    @ResponseBody
    public BaseWrapper deleteFileIsRead(HttpServletRequest request,String delStr){
        Cookie redisSessionCookie = CookiesUtil.getCookieByName(request, "redisSessionId");
        Users user = SessionUtils.getSessionInfo(request.getSession(), Users.class, new Users(),redisSessionCookie);
        return toBeReadService.deleteFileIsRead(delStr,user.getUserId());
    }

    /**
     * 未阅转已阅
     * 王禹萌
     * 2018-11-28
     * @param request
     * @param updateStr
     * @return
     */
    @RequestMapping("/updateFileIsRead")
    @ResponseBody
    public BaseWrapper updateFileIsRead(HttpServletRequest request,String updateStr, String userId,String flowId,String flowStep,String prcsId,String runName,String tableId) {
        Cookie redisSessionCookie = CookiesUtil.getCookieByName(request, "redisSessionId");
        Users user = SessionUtils.getSessionInfo(request.getSession(), Users.class, new Users(),redisSessionCookie);
        return toBeReadService.updateFileIsRead(updateStr,user.getUserId(),flowId,flowStep,prcsId,runName,tableId);
    }

    /**
     * 传阅人签收情况
     * wym
     * @param runId
     * @return
     */

    @RequestMapping("/queryFileIsRead")
    @ResponseBody
    public BaseWrapper queryFileIsRead(String runId,String prcsId,String flowPrcs){

        return toBeReadService.queryFileIsRead(runId,prcsId,flowPrcs);
    }

    /**
     * 文件传阅撤回
     * 王禹萌
     * 2018-11-30
     * @param runId
     * @param prcsId
     * @param flowPrcs
     * @return
     */
    @RequestMapping("/withdrawFileRead")
    @ResponseBody
    public BaseWrapper withdrawFileRead(String runId,Integer prcsId, Integer flowPrcs,String tabId,String tableName,Integer flowId){
        return toBeReadService.withdrawFileRead(runId,prcsId,flowPrcs,tabId,tableName,flowId);
    }

    /**
     * 判断点击事务提醒该条提醒是否有传阅功能、如果有则更新成已阅
     * 王禹萌
     * 2018-12-3
     * @param runId 流水号
     * @return
     */
    @RequestMapping("/querySmsIsRead")
    @ResponseBody
    public BaseWrapper querySmsIsRead(HttpServletRequest request,String runId,String prcsId){
        Cookie redisSessionCookie = CookiesUtil.getCookieByName(request, "redisSessionId");
        Users user = SessionUtils.getSessionInfo(request.getSession(), Users.class, new Users(),redisSessionCookie);
        return toBeReadService.querySmsIsRead(user.getUserId(),runId,prcsId);
    }

}

